<?php

namespace Cck\ArticlesSystem\Services;

use Cck\ArticlesSystem\Http\Models\HtmlTag;
use Illuminate\Database\Eloquent\Collection;

class HtmlTagService
{
    /**
     *
     * @var Collection|HtmlTag[]
     */
    protected $tags = null;

    public function __construct()
    {
        $this->tags = HtmlTag::query()->select(['tag', 'html'])->get()->keyBy('tag');
    }

    public function getTag(string $tagName): ?HtmlTag
    {
        return $this->tags->get($tagName);
    }

    public function getHtml(string $tag)
    {
        return $this->getTag($tag)->html ?? '';
    }
}
